package com.tuliomoura.got.guide.globals;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.widget.TextView;

import com.tuliomoura.got.guide.GuideApplication;

public class CustomTextView extends TextView
{

	public CustomTextView(Context context)
	{
		super(context);
	}
	
	public CustomTextView(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		setCustomFont(context, attrs);
	}
	
	public CustomTextView(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
		setCustomFont(context, attrs);
	}
	
	private void setCustomFont(Context context, AttributeSet attrs)
	{
		final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
		final String preferredFont = preferences.getString(GuideApplication.PREFERRED_FONT, null);
		if (preferredFont != null)
		{
			final FontsEnum font = FontsEnum.valueOf(preferredFont);
			setTypeface(GuideApplication.getFontByFontsEnum(font));
		}
		else
			setTypeface(Typeface.SERIF);
    }
}
